var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/help/ProjectEngineeringHelp/HelpContent.tsx
var HelpContent_exports = {};
__export(HelpContent_exports, {
  HelpContent: () => HelpContent
});
module.exports = __toCommonJS(HelpContent_exports);
var import_react = require("react");
var import_baseComponent = require("../../../baseComponent");
var import_functionalComponent = require("../../../functionalComponent");
var import_util = require("../../../util");
var import_ProjectEngineeringTree = __toESM(require("./ProjectEngineeringTree"));
var import_utils = require("./utils");
var tableProps = {
  rowSelected: false,
  rowChecked: true,
  cache: false,
  headerMenu: false,
  style: { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 }
};
var tableStyle = { borderStyle: "solid", borderColor: "var(--border-color-split, #f0f0f0)", borderWidth: 1 };
var { Header, Footer, MultipleButtons } = import_functionalComponent.BaseHelp;
function HelpContent() {
  const {
    request,
    ok,
    contentParams: {
      showTree = false,
      getFieldValue,
      columns,
      helpTitle,
      helpId,
      selectedArray,
      multiple,
      footer,
      treeProps
    },
    locale,
    randomKey
  } = (0, import_react.useContext)(import_functionalComponent.HelpContext);
  const btnRef = (0, import_react.useRef)();
  const rightTable = (0, import_react.useRef)();
  const MAIN_TABLE_KEY = `${helpId}_${randomKey}_main`;
  const getTable = (0, import_react.useCallback)((tableKey) => tableKey && import_util.iup.compIns[tableKey].getApi(), []);
  const getResult = () => {
    if (multiple) {
      const result = rightTable.current.getApi().getRows().map((r) => ({
        value: getFieldValue(r),
        label: getFieldValue(r, "label"),
        origin: { ...r }
      }));
      return result.length > 0 ? result : void 0;
    } else {
      const value = getTable(MAIN_TABLE_KEY).getSelectedData()[0];
      if (value) {
        return { value: getFieldValue(value), label: getFieldValue(value, "label"), origin: { ...value } };
      }
      return void 0;
    }
  };
  const toRight = (values) => {
    if (multiple) {
      btnRef.current.toRight(values);
    } else {
      ok(getResult());
    }
  };
  const onSearch = (value) => {
    getTable(MAIN_TABLE_KEY).query({ keyword: value });
  };
  const onDataLoad = (0, import_util.useRefCallback)((table) => {
    const { dataSource = [] } = table.getState() || {};
    const selectIndex = (0, import_utils.findFilterIndexes)(dataSource, (it) => (selectedArray || []).map((x) => x.id).includes(it.id));
    table.setSelected(selectIndex);
  });
  return /* @__PURE__ */ React.createElement(import_util.Layout, null, /* @__PURE__ */ React.createElement(Header, { title: helpTitle || "工程项目帮助" }), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { direction: "row", style: { padding: 5 } }, showTree && /* @__PURE__ */ React.createElement(import_util.Layout.Slider, { size: 240 }, /* @__PURE__ */ React.createElement(
    import_ProjectEngineeringTree.default,
    {
      getTable: () => getTable(MAIN_TABLE_KEY),
      multiple,
      treeProps,
      showTree
    }
  )), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { direction: "column", style: { marginLeft: 8 } }, /* @__PURE__ */ React.createElement(
    import_baseComponent.Search,
    {
      size: "small",
      allowClear: true,
      placeholder: locale.searchPlaceholder,
      onSearch,
      style: { marginBottom: 8, width: 300, alignSelf: "flex-end" }
    }
  ), /* @__PURE__ */ React.createElement(import_util.Layout.Flex, { direction: "column" }, /* @__PURE__ */ React.createElement(import_util.Layout.Flex, null, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Table,
    {
      style: tableStyle,
      id: MAIN_TABLE_KEY,
      columns,
      pagination: { hideOnSinglePage: false },
      autoLoad: true,
      request,
      response: (res) => ({ total: res.total ?? 0, record: res.list || [] }),
      rowSelection: {
        type: multiple ? [import_functionalComponent.TableSelectionModel.CHECKBOX, import_functionalComponent.TableSelectionModel.MULTIPLE_INTERVAL] : import_functionalComponent.TableSelectionModel.ROW
      },
      onRow: (rowIndex, table) => ({
        onDoubleClick: () => toRight([table.getRow(rowIndex)])
      }),
      onDataLoad
    }
  )))), multiple && /* @__PURE__ */ React.createElement(
    MultipleButtons,
    {
      getRowKey: getFieldValue,
      outRef: btnRef,
      getActiveTable: () => getTable(MAIN_TABLE_KEY),
      getResultTable: () => rightTable.current.getApi()
    }
  ), multiple && /* @__PURE__ */ React.createElement(import_util.Layout.Slider, { size: 200 }, /* @__PURE__ */ React.createElement(
    import_functionalComponent.Table,
    {
      ...tableProps,
      columns,
      dataSource: selectedArray,
      ref: rightTable,
      onRow: (rowIndex) => ({
        onDoubleClick: () => btnRef.current.toLeft(rowIndex)
      })
    }
  ))), /* @__PURE__ */ React.createElement(Footer, { getResult }, footer && /* @__PURE__ */ React.createElement("span", { style: { flex: 1, width: 0 }, children: footer })));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  HelpContent
});
